package com.hq.door.dto;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import com.hq.door.pojo.TParent;

/**
 * 作者：袁健宝
 * 日期：2016年12月31日 上午4:23:17
 */
public class ParentDto {
	
	/**
	 * 转成前端数据 parent
	 * @param tparent
	 * @return
	 */
	public static Parent writeParent(TParent tparent){
		Parent parent = null;
	    if (tparent != null){
	    	parent = new Parent();
	    	parent.setId(tparent.getId());
	    	parent.setUserName(tparent.getName());
	    	parent.setPassword(tparent.getPassword());
	    }
	    return parent;
    }
	
	/**
	 * 转成前端数据 parent集合
	 * @param tparents
	 * @return
	 */
	public static Parent[] writeParent(Collection tparents){
		List list = new ArrayList();
		if (tparents != null){
			Iterator iterator = tparents.iterator();
            while (iterator.hasNext())
            {
            	Parent parent = writeParent((TParent) iterator.next());
            	if(parent!=null){
            		list.add(parent);
            	}
            }
		}
		Major[] array = new Major[list.size()]; 
		return (Parent[]) list.toArray(array);
	}
	
	/**
	 * 转换成数据库对象 pojo
	 * @param parent	
	 * @return
	 */
	public static TParent readParent(Parent parent){
		TParent tparent = null;
	    if (parent != null){
	    	tparent = new TParent();
	    	tparent.setId(parent.getId());
	    	tparent.setName(parent.getUserName());
	    	tparent.setPassword(parent.getPassword());
	    }
	    return tparent;
    }
	
}
